Vue.js lastIndexOf method: The lastIndexOf() method of the Vue.js String class is used to search a string for a specified character or string, starting at the end of the string and returning the index position of the matched substring. The lastIndexOf() method can be used in many ways, such as finding a substring within a string or finding the location of the last instance of a certain character in a string. This means it will start at the end of the string and work its way to the beginning, returning the index number of the last occurrence of a specified value. If it does not find a match, then it simply returns -1, which can be seen as an indication of “not found.” The lastIndexOf() method is case sensitive. This means that if one were to search for the character “A” in a string containing both upper- and lower case letters, it would only find the occurrences of “A” and not those of “a.” In these tutorials, we will learn how to find the last index of the last index of a substring in a string with the help of Vue JS. In Vue JS, the `lastIndexOf()` method can be used to find the last index of a substring in a string.
Vue Js find the last occurrence of a character in a string ?
Vue.js provides a powerful string method, “lastindexof(),” which can be used to find the last occurrence of a character in a string.
Using the lastIndexOf() method in Vue.js can be a useful tool when looking for the position of a specific string in an array or
Vue Js Get last occurance of Character in a String
<div id="app">
<p>{{text}}</p>
<p>Search String:{{searchString}}</p>
<button @click="myFunction">Get Position</button>
<p>Last Index :: {{results}}</p>
</div>
<script type="module">
import { createApp } from 'vue'
createApp({
data()
{
return{
text : 'Hello David! David, you look so strong and healthy .',
searchString:'David',
results:''
}
},
methods:{
myFunction(){
this.results = this.text.indexOf(this.searchString);
},
}
}).mount('#app')
</script>
Output of above example
Vue Js String Last Index of Case Sensitive Example
An example of case sensitive usage of the Vue.js lastIndexOf method is when you want to search for a specific string within a given text The lastIndexOf() method of the JavaScript Vue library is case-sensitive and useful for finding the index of the last occurrence of a specified value in a string.
Vue Js Case- Sensitive Example.
<div id="app">
<p>{{text}}</p>
<p>Search String:{{searchString}}</p>
<button @click="myFunction">Get Position</button>
<p>Last Index :: {{results}}</p>
</div>
<script type="module">
import { createApp } from 'vue'
createApp({
data()
{
return{
text : 'Hello David! David, you look so strong and healthy .',
searchString:'david',
results:''
}
},
methods:{
myFunction(){
this.results = this.text.indexOf(this.searchString);
},
}
}).mount('#app')
</script>